--- 模块功能：HX8379C驱动芯片LCD命令配置
-- @author openLuat
-- @module ui.mipi_lcd_HX8379C
-- @license MIT
-- @copyright openLuat
-- @release 2022.01.07
--[[
注意：MIPI接口

module(...,package.seeall)
]] --[[
函数名：init
功能  ：初始化LCD参数
参数  ：无
返回值：无
]]

require "pins"

local function init()
    local para = {
        width = 480, -- 分辨率宽度，
        height = 864, -- 分辨率高度
        bpp = 16, -- MIPI LCD直接写16，暂不支持其他配置
        bus = disp.BUS_MIPI, -- LCD专用SPI引脚接口，不可修改
        xoffset = 0, -- X轴偏移
        yoffset = 0, -- Y轴偏移
        freq = 125000000, -- mipi时钟最高为500000000 最低为125000000
        pinrst = pio.P0_20, -- reset，复位引脚,MIPI屏幕必须填写
        pinrs = 0xffff, -- mipi不需要rs脚，直接写0xffff

        ---- porch_vs porch_vbp porch_vfp porch_hs porch_hbp porch_hfp 这6个参数可以不配置
        ---- 软件有默认的配置。一般mipi屏会兼容多套参数。也可以根据厂商提供的参数进行修改
        ---- （480+30+30+10）*（854+15+8+2）* 16
        --porch_vs = 2,
        porch_vbp = 3,
        --porch_vfp = 13,
        --porch_hs = 10,
        -- porch_hbp = 30,
        --porch_hfp = 30,

        -- continue_mode 可以不配置底层默认为0. 配置后一直处于高速continue 模式
        --continue_mode = 1,

        -- 初始化命令
        -- 前两个字节表示类型：0001表示延时，0000或者0002表示命令，0003表示数据
        -- 延时类型：后两个字节表示延时时间（单位毫秒）
        -- 命令类型：后两个字节命令的值
        -- 数据类型：后两个字节数据的值
        -- 现在MIPI LCD 只支持,lane 2线,RGB565格式

        initcmd = {
0x000200B9,0x000300FF,0x00030083,0x00030079,

0x000200B1,0x00030044,0x00030016,0x00030016,0x00030031,0x00030031,0x00030090,0x000300D0,0x000300EE,0x00030094,0x00030080,0x00030038,0x00030038,0x000300F8,0x00030022,0x00030022,0x00030022,

0x000200B2,0x00030082,0x000300FE,0x0003000D,0x0003000A,0x00030020,0x00030050,0x00030011,0x00030042,0x0003001D,

0x000200B4,0x00030001,0x00030078,0x00030001,0x00030078,0x00030001,0x00030078,0x00030022,0x0003007F,0x00030023,0x0003007F,

0x000200C7,0x00030000,0x00030000,0x00030000,0x000300C0,

0x000200CC,0x00030002,

0x000200D2,0x00030011,

0x000200D3,0x00030000,0x00030007,0x00030000,0x0003003C,0x00030014,0x0003000A,0x0003000A,0x00030032,0x00030010,0x00030002,0x00030000,0x00030002,0x00030003,0x00030070,0x00030003,0x00030070,0x00030000,0x00030008,0x00030000,0x00030008,0x00030037,0x00030033,0x00030006,0x00030006,0x00030037,0x00030006,0x00030006,0x00030037,0x0003000B,

0x000200D5,0x00030019,0x00030019,0x00030018,0x00030018,0x0003001A,0x0003001A,0x0003001B,0x0003001B,0x00030002,0x00030003,0x00030000,0x00030001,0x00030006,0x00030007,0x00030004,0x00030005,0x00030020,0x00030021,0x00030022,0x00030023,0x00030018,0x00030018,0x00030018,0x00030018,0x00030018,0x00030018,0x00030018,0x00030018,0x00030018,0x00030018,0x00030018,0x00030018,0x00030000,0x00030000,

0x000200D6,0x00030018,0x00030018,0x00030019,0x00030019,0x0003001A,0x0003001A,0x0003001B,0x0003001B,0x00030003,0x00030002,0x00030005,0x00030004,0x00030007,0x00030006,0x00030001,0x00030000,0x00030023,0x00030022,0x00030021,0x00030020,0x00030018,0x00030018,0x00030018,0x00030018,0x00030018,0x00030018,0x00030018,0x00030018,0x00030018,0x00030018,0x00030018,0x00030018,

0x000200E0,0x00030000,0x00030000,0x00030000,0x0003000C,0x0003000C,0x0003003F,0x00030021,0x00030031,0x00030007,0x0003000C,0x0003000F,0x00030019,0x00030011,0x00030016,0x00030018,0x00030016,0x00030016,0x00030008,0x00030012,0x00030013,0x00030018,0x00030000,0x00030000,0x00030000,0x0003000B,0x0003000D,0x0003003F,0x00030020,0x00030031,0x00030008,0x0003000D,0x0003000F,0x00030019,0x00030012,0x00030016,0x00030019,0x00030016,0x00030016,0x00030008,0x00030014,0x00030014,0x00030019,

0x000200B6,0x0003004D,0x0003004D,

            0x00020011,0x00030000,
	    0x00010078,
            0x00020029,0x00030000,
	    0x00010032,
        },
        -- 休眠命令
        --sleepcmd = {0x00020028, 0x00020010},
        ---- 唤醒命令
        --wakecmd = {0x00020011, 0x00020029}
    }
    disp.init(para)
    disp.clear()
    disp.update()
end

-- VLCD电压域配置
pmd.ldoset(15, pmd.LDO_VIBR)

-- 背光配置
function backlightopen(on)
    if on then
        pins.setup(pio.P0_8, 1)
        log.info("mipi_lcd_GC9503V 你打开了背光")
    else
        pins.setup(pio.P0_8, 0)
        log.info("mipi_lcd_GC9503V 你关闭了背光")
    end
end
backlightopen(true)
-- 初始化
init()
